package com.yueqian.sign;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.Spinner;

import com.yueqian.sign.model.Classes;
import com.yueqian.sign.model.Course;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ViewPager vp_content;
    private Spinner spinner_classes;
    private Spinner spinner_course;
    private RadioButton rb_sign;
    private RadioButton rb_record;

    private SignView signView;
    private RecordView recordView;

    private List<View> vpList;
    private List<Classes> classes;
    private List<Course> courses;

    private ContentAdapter contentAdapter;
    private MyAdapter classesAdapter;
    private MyAdapter courseAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initUI();
        initData();
    }

    /**
     * 初始化UI控件绑定
     */
    public void initUI() {
        vp_content = findViewById(R.id.vp_content);//为什么不用强转，因为泛型
        spinner_classes = findViewById(R.id.spinner_classes);
        spinner_course = findViewById(R.id.spinner_course);
        rb_sign = findViewById(R.id.rb_sign);
        rb_record = findViewById(R.id.rb_record);
    }

    public void initData() {
        signView = new SignView(this);
        recordView = new RecordView(this);
        vpList = new ArrayList<View>();
        vpList.add(signView.getView());
        vpList.add(recordView.getView());
        contentAdapter = new ContentAdapter(this, vpList);
        vp_content.setAdapter(contentAdapter);

        classes = new ArrayList<>();
        classes.add(new Classes(1, "软件技术17"));
        classes.add(new Classes(2, "计算网络技术"));
        classesAdapter = new ClassesAdapter(this, classes);
        spinner_classes.setAdapter(classesAdapter);

        courses = new ArrayList<>();
        courses.add(new Course(1, "Android开发", new Date(), new Date(System.currentTimeMillis() + 10000000)));
        courses.add(new Course(1, "Java入门基础", new Date(), new Date(System.currentTimeMillis() + 10000000)));
        courseAdapter = new CourseAdapter(this, courses);
        spinner_course.setAdapter(courseAdapter);

        rb_sign.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }
}
